﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Nha_Hang_Khach_San.NHKSServiceReference;
using System.ServiceModel;

namespace Nha_Hang_Khach_San.Khach_San
{
    public partial class SoDoKhachSan : UserControl
    {
        public SoDoKhachSan()
        {
            InitializeComponent();
            //dataGrid1.Loaded += new RoutedEventHandler(dataGrid1_Loaded);
            lbKhuVuc.Loaded += new RoutedEventHandler(lbKhuVuc_Loaded);
            lbPhong.Loaded += new RoutedEventHandler(lbPhong_Loaded);
        }

        #region Quản lý khu vực
        private void mitDoiTen_Click(object sender, RoutedEventArgs e)
        {
            string tenKV = ((SoDoKhuVuc)lbKhuVuc.SelectedItem).TenKhuVuc;
            MessageBox.Show("Đổi tên:" + tenKV + "chua làm");
        }

        private void mitThemKhuVuc_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Chưa làm");
        }

        private void mitXoaKhuVuc_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Chưa làm");
        }
        #endregion

        void lbKhuVuc_Loaded(object sender, RoutedEventArgs e)
        {
            NHKSServiceClient client = new NHKSServiceClient();
            BasicHttpBinding bind = new BasicHttpBinding();
            EndpointAddress end = new EndpointAddress("http://localhost:3418/NHKSService.svc?wsdl");
            client.GetDSKhuVucCompleted += new EventHandler<GetDSKhuVucCompletedEventArgs>(client_GetDSKhuVucCompleted);
            client.GetDSKhuVucAsync();
        }

        void client_GetDSKhuVucCompleted(object sender, GetDSKhuVucCompletedEventArgs e)
        {
            lbKhuVuc.ItemsSource = e.Result;
        }

        void lbPhong_Loaded(object sender, RoutedEventArgs e)
        {
            NHKSServiceClient client = new NHKSServiceClient();
            BasicHttpBinding bind = new BasicHttpBinding();
            EndpointAddress end = new EndpointAddress("http://localhost:3418/NHKSService.svc?wsdl");
            client.GetDSPhongCompleted += new EventHandler<GetDSPhongCompletedEventArgs>(client_GetDSPhongCompleted);
            client.GetDSPhongAsync();
        }

        //void dataGrid1_Loaded(object sender, RoutedEventArgs e)
        //{
        //    NHKSServiceClient client = new NHKSServiceClient();
        //    BasicHttpBinding bind = new BasicHttpBinding();
        //    EndpointAddress end = new EndpointAddress("http://localhost:2917/NHKSService.svc?wsdl");
        //    client.GetDSPhongCompleted += new EventHandler<GetDSPhongCompletedEventArgs>(client_GetDSPhongCompleted);
        //    client.GetDSPhongAsync();
        //}

        void client_GetDSPhongCompleted(object sender, GetDSPhongCompletedEventArgs e)
        {
            lbPhong.ItemsSource = e.Result;
        }

        private void lbKhuVuc_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
        }

        private void lbKhuVuc_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            if(lbKhuVuc.SelectedItems.Count>0)
            {
                ctmenuKhuVuc.IsOpen = true;
            }
        }

        private void lbPhong_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
        }

        private void lbPhong_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            if(lbPhong.SelectedItems.Count>0)
            {
                ctmenuPhongTrong.IsOpen = true;
            }
        }

        private void mitChiTietPhong_Click(object sender, RoutedEventArgs e)
        {
            string tenPhong = ((SoDoPhong)lbPhong.SelectedItem).TenPhong;
            CTPhong ctPhong = new CTPhong(tenPhong);
            ctPhong.Show();
        }

        private void mitPhieuThue_Click(object sender, RoutedEventArgs e)
        {
            string tenPhong = ((SoDoPhong)lbPhong.SelectedItem).TenPhong;
            PhieuThuePhong pThuePhong = new PhieuThuePhong(tenPhong);
            pThuePhong.Show();
        }

        private void dpNgayXem_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void mitCapNhat_Click(object sender, RoutedEventArgs e)
        {

        }

        private void mitChinhSua_Click(object sender, RoutedEventArgs e)
        {

        }

        private void mitXoa_Click(object sender, RoutedEventArgs e)
        {

        }
    }
}
